{% extends "orga/base.html" %}

{% load compress %}
{% load event_tags %}
{% load i18n %}
{% load rules %}
{% load static %}

{% block scripts %}
    {% compress js %}
        <script defer src="{% static "orga/js/submission_filter.js" %}"></script>
    {% endcompress %}
{% endblock scripts %}

{% block stylesheets %}
    {% if timeline_data %}
        <link rel="alternate" hreflang="en" type="application/rss+xml" title="{% translate "Proposal feed" %}" href="{{ request.event.orga_urls.submission_feed }}">
    {% endif %}
{% endblock stylesheets %}

{% block extra_title %}{{ page_obj.paginator.count }} {% blocktranslate trimmed count count=page_obj.paginator.count %}session{% plural %}sessions{% endblocktranslate %} :: {% endblock extra_title %}

{% block content %}
    {% has_perm "base.create_submission" request.user request.event as can_create_submission %}
    {% has_perm "base.state_change_submission" request.user request.event as can_change_submission %}
    {% has_perm "base.orga_list_speakerprofile" request.user request.event as can_view_speakers %}
    {% has_perm "base.send_queuedmail" request.user request.event as can_send_mails %}
    <h2 class="d-flex align-items-center">
        <span>
            {{ page_obj.paginator.count }}
            {% blocktranslate trimmed count count=page_obj.paginator.count %}
                session
            {% plural %}
                sessions
            {% endblocktranslate %} 
        </span>
        <p class="flip ml-auto">
            <div>
                {% if can_send_mails %}
                    <a class="btn btn-outline-info mt-2" href="{{ request.event.orga_urls.compose_mails_sessions }}{% querystring page='' %}">
                        <i class="fa fa-envelope"></i>
                        {% translate "Send email" %}
                    </a>
                {% endif %}
                {% if pending_changes and can_change_submission %}
                    <a class="btn btn-info mt-2" href="{{ request.event.orga_urls.apply_pending }}{% querystring %}">
                        {% translate "Apply pending changes" %} ({{ pending_changes }})
                    </a>
                {% endif %}
                {% if can_create_submission %}
                    <a href="{{ request.event.orga_urls.new_submission }}" class="btn btn-info mt-2">
                        <i class="fa fa-plus"></i> {% translate "Add new session or proposal" %}
                    </a>
                    <a class="btn btn-link" href="{{ request.event.orga_urls.submission_feed }}" title="{% translate 'Proposal feed' %}">
                        <i class="fa fa-feed"></i>
                    </a>
                {% endif %}
            </div>
            <div>
                {% include "orga/event/component_link.html" %}
            </div>
        </p>
    </h2>

    {% include "orga/includes/submission_filter_form.html" %}

    <div class="table-responsive-sm">
        <table class="table table-sm table-flip table-sticky">
            <thead>
                <tr>
                    <th>
                        {% if request.event|get_feature_flag:"use_tracks" and filter_form.track %}
                            <a href="{% querystring sort="track__name" %}"><i class="fa fa-caret-down" title="{% translate "Sort (a-z)" %}"></i></a>
                            <a href="{% querystring sort="-track__name" %}"><i class="fa fa-caret-up" title="{% translate "Sort (z-a)" %}"></i></a>
                        {% endif %}
                    </th>
                    <th>
                        {% translate "Title" %}
                        <a href="{% querystring sort="title" %}"><i class="fa fa-caret-down" title="{% translate "Sort (a-z)" %}"></i></a>
                        <a href="{% querystring sort="-title" %}"><i class="fa fa-caret-up" title="{% translate "Sort (z-a)" %}"></i></a>
                    </th>
                    {% if can_view_speakers %}<th>{{ phrases.schedule.speakers }}</th>{% endif %}
                    {% if show_submission_types %}
                        <th>
                            {% translate "Type" %}
                            <a href="{% querystring sort="submission_type__name" %}"><i class="fa fa-caret-down" title="{% translate "Sort (a-z)" %}"></i></a>
                            <a href="{% querystring sort="-submission_type__name" %}"><i class="fa fa-caret-up" title="{% translate "Sort (z-a)" %}"></i></a>
                        </th>
                    {% endif %}
                    <th>
                        {% translate "State" %}
                        <a href="{% querystring sort="state" %}"><i class="fa fa-caret-down" title="{% translate "Sort (a-z)" %}"></i></a>
                        <a href="{% querystring sort="-state" %}"><i class="fa fa-caret-up" title="{% translate "Sort (z-a)" %}"></i></a>
                    </th>
                    {% if can_change_submission %}
                        <th>
                            {% translate "Featured" %} <i class="fa fa-question-circle" data-toggle="tooltip" title="{% translate "Show this session on the list of featured sessions, once it was accepted" %}"></i>
                            <a href="{% querystring sort="-is_featured" %}"><i class="fa fa-caret-down"></i></a>
                            <a href="{% querystring sort="is_featured" %}"><i class="fa fa-caret-up"></i></a>
                        </th>
                        <th></th>
                    {% endif %}
                </tr>
            </thead>
            <tbody>
                {% for submission in submissions %}
                    <tr>
                        <td class="text-center">
                            {% if request.event|get_feature_flag:"use_tracks" and submission.track %}
                                {% if not submission.is_anonymised %}
                                    <div class="color-square" style="background-color: {{ submission.track.color }}" title="{{ submission.track.name }}">
                                    </div>
                                {% else %}
                                    <i class="fa fa-user-secret" style="color: {{ submission.track.color }}" title="{{ submission.track.name }}, {% translate "anonymised" %}" aria-hidden="true"></i>
                                {% endif %}
                            {% else %}
                                {% if submission.anonymised %}
                                    <i class="fa fa-user-secret" style="color: #888" title="{% translate "anonymised" %}" aria-hidden="true"></i>
                                {% endif %}
                            {% endif %}
                        </td>
                        <td>
                            <a href="{{ submission.orga_urls.base }}">
                                {% if can_view_speakers %}
                                    {{ submission.title }}
                                {% else %}
                                    {{ submission.anonymised.title|default:submission.title }}
                                {% endif %}
                            </a>
                        </td>
                        {% if can_view_speakers %}
                            <td>
                                {% for speaker in submission.speakers.all %}
                                    <a href="{% url "orga:speakers.view" event=request.event.slug code=speaker.code %}">
                                        {% include "orga/includes/user_name.html" with user=speaker %}
                                    </a><br>
                                {% endfor %}
                            </td>
                        {% endif %}
                        {% if show_submission_types %}<td>{{ submission.submission_type.name }}</td>{% endif %}
                        <td>

                            {% if can_change_submission %}
                                {% include "orga/submission/state_dropdown.html" with submission=submission %}
                            {% else %}
                                {% include "cfp/event/fragment_state.html" with state=submission.state as_badge=True %}
                            {% endif %}

                        </td>
                        {% if can_change_submission %}
                            <td class="submission_featured">
                                <div class="mt-1 form-check" title="{% translate "Show this proposal in the list of featured sessions." %}">
                                    <input
                                        type="checkbox"
                                        id="featured_{{ submission.code }}"
                                        data-id="{{ submission.code }}"
                                        class="submission_featured"
                                        {% if submission.is_featured %}checked{% endif %}
                                    >
                                    <label for="featured_{{ submission.code }}"></label>
                                </div>
                                <i class="working fa fa-spinner fa-spin d-none"></i>
                                <i class="done fa fa-check d-none text-success"></i>
                                <i class="fail fa fa-times d-none"></i>
                            </td>
                            <td class="text-right">
                                <a href="{{ submission.orga_urls.edit }}" title="{{ phrases.base.edit }}" class="btn btn-sm btn-info">
                                    <i class="fa fa-edit"></i>
                                </a>
                                <a href="{{ submission.orga_urls.delete }}?from=list" title="{{ phrases.base.delete_button }}" class="btn btn-sm btn-danger">
                                    <i class="fa fa-trash"></i>
                                </a>
                            </td>
                        {% endif %}
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

    {% include "orga/includes/pagination.html" %}

{% endblock content %}
